home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 1999 January / maximum-cd-1999-01.iso / Benchmarks / 12 Step / MusicMatch Jukebox / mmsetup.EXE / data1.cab / Help_Files / WebHelp.cab / hhapplet / CanvasButton.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-03-27  |  2.9 KB  |  156 lines

  1. package hhapplet;
  2.  
  3. import java.awt.Canvas;
  4. import java.awt.Color;
  5. import java.awt.Component;
  6. import java.awt.Dimension;
  7. import java.awt.Event;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.Rectangle;
  11. import java.awt.image.ImageObserver;
  12. import java.util.Vector;
  13.  
  14. public class CanvasButton extends Canvas {
  15.    protected Rectangle inside;
  16.    protected Image img;
  17.    protected Vector listeners;
  18.    protected boolean button_push_state;
  19.  
  20.    public void paint(Graphics var1) {
  21.       var1.setColor(((Component)this).getBackground());
  22.       var1.fillRect(0, 0, ((Component)this).bounds().width, ((Component)this).bounds().height);
  23.       if (this.img != null) {
  24.          var1.drawImage(this.img, 2, 2, (ImageObserver)null);
  25.       }
  26.  
  27.       if (this.button_push_state) {
  28.          this.paintBorderIn(var1);
  29.       } else {
  30.          this.paintBorderOut(var1);
  31.       }
  32.    }
  33.  
  34.    public CanvasButton(Image var1) {
  35.       this();
  36.       this.img = var1;
  37.    }
  38.  
  39.    public CanvasButton() {
  40.       this.img = null;
  41.       this.listeners = new Vector();
  42.       this.button_push_state = false;
  43.       ((Component)this).setBackground(new Color(192, 192, 192));
  44.    }
  45.  
  46.    public void paintBorderOut(Graphics var1) {
  47.       Rectangle var2 = ((Component)this).bounds();
  48.       Color var3 = ((Component)this).getBackground().brighter();
  49.       Color var4 = var3.darker();
  50.       Color var5 = var4.darker();
  51.       Color var6 = var5.darker();
  52.       var1.setColor(var3);
  53.       var1.drawLine(0, 0, var2.width - 1, 0);
  54.       var1.drawLine(0, 0, 0, var2.height - 1);
  55.       var1.setColor(var4);
  56.       var1.drawLine(1, 1, var2.width - 2, 1);
  57.       var1.drawLine(1, 1, 1, var2.height - 2);
  58.       var1.setColor(var6);
  59.       var1.drawLine(var2.width - 2, 1, var2.width - 2, var2.height - 2);
  60.       var1.drawLine(1, var2.height - 2, var2.width - 2, var2.height - 2);
  61.       var1.setColor(var5);
  62.       var1.drawLine(var2.width - 1, 1, var2.width - 1, var2.height - 1);
  63.       var1.drawLine(0, var2.height - 1, var2.width - 1, var2.height - 1);
  64.    }
  65.  
  66.    public void update(Graphics var1) {
  67.       this.paint(var1);
  68.    }
  69.  
  70.    public void paintBorderIn(Graphics var1) {
  71.       Rectangle var2 = ((Component)this).bounds();
  72.       Color var3 = ((Component)this).getBackground().brighter();
  73.       Color var4 = var3.darker();
  74.       Color var5 = var4.darker();
  75.       Color var6 = var5.darker();
  76.       var1.setColor(var6);
  77.       var1.drawLine(0, 0, var2.width - 1, 0);
  78.       var1.drawLine(0, 0, 0, var2.height - 1);
  79.       var1.setColor(var5);
  80.       var1.drawLine(1, 1, var2.width - 2, 1);
  81.       var1.drawLine(1, 1, 1, var2.height - 2);
  82.       var1.setColor(var4);
  83.       var1.drawLine(var2.width - 2, 1, var2.width - 2, var2.height - 2);
  84.       var1.drawLine(1, var2.height - 2, var2.width - 2, var2.height - 2);
  85.       var1.setColor(var3);
  86.       var1.drawLine(var2.width - 1, 1, var2.width - 1, var2.height - 1);
  87.       var1.drawLine(0, var2.height - 1, var2.width - 1, var2.height - 1);
  88.    }
  89.  
  90.    public void removeButtonPushEventListener(ButtonPushEventListener var1) {
  91.       this.listeners.removeElement(var1);
  92.    }
  93.  
  94.    public Dimension preferredSize() {
  95.       return this.img != null ? new Dimension(this.img.getWidth(this) + 4, this.img.getHeight(this) + 4) : new Dimension(20, 20);
  96.    }
  97.  
  98.    public void addButtonPushEventListener(ButtonPushEventListener var1) {
  99.       this.listeners.addElement(var1);
  100.    }
  101.  
  102.    public boolean handleEvent(Event var1) {
  103.       if (var1.id == 501) {
  104.          this.button_push_state = true;
  105.          ((Component)this).repaint();
  106.          return true;
  107.       } else if (var1.id == 502 && this.button_push_state) {
  108.          this.button_push_state = false;
  109.          ((Component)this).repaint();
  110.          Rectangle var3 = ((Component)this).bounds();
  111.          var3.x = 0;
  112.          var3.y = 0;
  113.          if (var3.inside(var1.x, var1.y)) {
  114.             this.doAction(var1);
  115.          }
  116.  
  117.          return true;
  118.       } else if (var1.id == 506) {
  119.          Rectangle var2 = ((Component)this).bounds();
  120.          var2.x = 0;
  121.          var2.y = 0;
  122.          if (!var2.inside(var1.x, var1.y)) {
  123.             if (this.button_push_state) {
  124.                this.button_push_state = false;
  125.                ((Component)this).repaint();
  126.             }
  127.          } else if (!this.button_push_state) {
  128.             this.button_push_state = true;
  129.             ((Component)this).repaint();
  130.          }
  131.  
  132.          return true;
  133.       } else {
  134.          return false;
  135.       }
  136.    }
  137.  
  138.    protected void doAction(Event var1) {
  139.       ButtonPushEvent var3 = new ButtonPushEvent(this, var1.x, var1.y);
  140.       synchronized(this){}
  141.  
  142.       Vector var2;
  143.       try {
  144.          var2 = (Vector)this.listeners.clone();
  145.       } catch (Throwable var9) {
  146.          throw var9;
  147.       }
  148.  
  149.       for(int var4 = 0; var4 < var2.size(); ++var4) {
  150.          ButtonPushEventListener var5 = (ButtonPushEventListener)this.listeners.elementAt(var4);
  151.          var5.notifyButtonPushEvent(var3);
  152.       }
  153.  
  154.    }
  155. }
  156.